﻿using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;
using Sharp.Portal.Configuration;
using Sharp.Portal.Mvc;
using PartialViewResult = Ext.Net.MVC.PartialViewResult;

namespace Sharp.WebBooter.Areas.Platform.Controllers
{
    [Authorize]
    public class SettingController : Controller
    {
        [AutomaticTemplate]
        public ActionResult Index(string containerId)
        {
            var model = SystemConfigManage.Read<PlatformInfo>();
            return new PartialViewResult
            {
                Model = model,
                ContainerId = containerId,
                RenderMode = RenderMode.AddTo
            };
        }

        public ActionResult SystemConfig()
        {
            return View("SystemConfig");
        }

        public ActionResult Save(PlatformInfo config)
        {

            if (config == null)
            {
                X.Msg.Info("提交数据出错。");
                return this.FormPanel();
            }

            SystemConfigManage.Save(config);

            X.Msg.Info("配置已保存。");

            return this.FormPanel();
        }
    }
}